﻿using System;
using System.Collections.Generic;
using System.Text;
using IBatisNet.Extend;
using System.Reflection;
using System.IO;
using IBatisNet.DataMapper.Configuration;

namespace ExpertMIS.Brokers
{
    public class ExpertMISBaseBroker : BaseBroker
    {
        private static log4net.ILog _log = log4net.LogManager.GetLogger(typeof(ExpertMISBaseBroker));

        private static IBatisNet.DataMapper.ISqlMapper _sqlMapper = null;

        private IBatisNet.DataMapper.ISqlMapper CreateSqlMapper()
        {
            try
            {
                Assembly assembly = Assembly.Load("ExpertMISBrokersLib");
                Stream stream = assembly.GetManifestResourceStream("ExpertMIS.Brokers.Config.sqlmap.config");
                DomSqlMapBuilder builder = new DomSqlMapBuilder();
                return builder.Configure(stream);
            }
            catch
            {
                throw;
            }
        }

        protected override IBatisNet.DataMapper.ISqlMapper GetSqlMapper()
        {
            if (null == _sqlMapper)
            {
                _sqlMapper = CreateSqlMapper();
            }

            return _sqlMapper;
        }

        protected log4net.ILog Logger
        {
            get
            {
                return _log;
            }
        }
    }
}
